package com.yan.json;

import com.alibaba.fastjson.JSON;
import com.yan.jackson.Student;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;

/**
 * @author taoge
 * @Date 2024/8/13 15:42
 * @Description 文件读取json文件
 */
public class JsonDemo4 {
    public static void main1(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("day18_code/src/com/yan/json/Json1.json"));
        String line = null;
        while((line = br.readLine()) != null){
            String stu = line;
            Student student = JSON.parseObject(stu, Student.class);
            System.out.println(student);
        }



    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("day18_code/src/com/yan/json/Json2.json"));

        StringBuffer stu = new StringBuffer();
        String line = null;

        while((line = br.readLine()) != null){
            stu.append(line.trim());
        }

        br.close();
        String newStu = stu.toString();
        List<Student> students = JSON.parseArray(newStu, Student.class);
        System.out.println(students);
    }
}
